<?php echo $javascript->link('filter_actions'); ?>
<div class="cashes view">
    <h2><?php __('Caja Grande'); ?></h2>
    <dl>
<?php
$i = 0;
$class = ' class="altrow"';
?>
        <dt<?php if ($i % 2 == 0) echo $class; ?>><?php __('Monto Actual'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class; ?>>
<?php echo '$' . $cash['BigCash']['actual_amount']; ?>
            &nbsp;
        </dd>
        <dt<?php if ($i % 2 == 0) echo $class; ?>><?php __('Última Modificación'); ?></dt>
        <dd<?php if ($i++ % 2 == 0) echo $class; ?>>
<?php echo date('d/m/Y H:i:s', strtotime($cash['BigCash']['modified'])); ?>
            &nbsp;
        </dd>
    </dl>
</div>
<div class="actions specific">
    <h3><?php __('Acciones'); ?></h3>
    <ul>
        <li><?php echo $this->Html->link(__('Agregar Movimiento Simple', true), array('controller' => 'big_cash_movements', 'action' => 'add')); ?> </li>
        <li><?php echo $this->Html->link(__('Transferir de Caja Grande a Caja Chica', true), array('controller' => 'big_cash_movements', 'action' => 'exportar_hacia_caja_chica')); ?> </li>
        <li><?php echo $this->Html->link(__('Transferir de Caja Chica a Caja Grande', true), array('controller' => 'big_cash_movements', 'action' => 'importar_desde_caja_chica')); ?> </li>
    </ul>
</div>
   <a href="" class="filtro_a" onclick="show_filter();
    return false;"><?php echo __('Filtro', true); ?></a>
<input type="hidden" id="input_filtro" value="1">
<div id="filtro_busqueda" class="filtro" style="display: block">
    <fieldset>
<?php echo $form->create('BigCash', array('url' => array('controller' => 'big_cashes', 'action' => 'view'))); ?>
        <?php
        echo $form->input('user_id', array('label' => 'Usuario', 'options' => $users, 'empty' => 'Todos','div'=>array('style'=>'float:left;')));
        echo $form->input('type', array('label' => 'Acción', 'options' => array('' => 'Todas', 'in' => 'Entrada', 'out' => 'Salida'),'div'=>array('style'=>'float:left; clear:none; margin-left: 10px;')));
        echo $form->input('movement', array('label' => 'Tipo', 'options' => array('' => 'Todos', 'simple' => 'Simple', 'bank' => 'Depósito Bancario', 'transfer_cash' => 'Transferencia Caja Chica', 'job_payment'=>'Pago Saldo Trabajo'),'div'=>array('style'=>'float:left; clear:none; margin-left: 10px;')));
        echo $form->input('amount', array('label' => 'Monto'));
        ?>
        <div class="date_range">
            <label>Rango de Fechas</label>
<?php
echo $form->input('date_from', array('label' => false));
?>
            <span>-</span>
            <?php
            echo $form->input('date_to', array('label' => false));
            ?>
            <span><?php echo $this->Html->link(__('Últimos 5 Días', true), array(), array('onclick' => 'fecha_semana(); return false;')); ?></span>
            <?php
            echo $form->input('hidden_actual_date', array('type' => 'hidden', 'value' => date('d/m/Y')));
            echo $form->input('hidden_week_date', array('type' => 'hidden', 'value' => date('d/m/Y', strtotime('-5 day', strtotime(date('Y-m-d H:i:s'))))));
            ?>

        </div>
<?php
echo $form->submit(__('Filtrar', true));
echo $form->end();
?>
    </fieldset>
</div>
<div class="related">
    <h3><?php __('Movimientos Relacionados'); ?></h3>
<?php
$total_entradas = 0;
$total_salidas = 0;

    ?>
        <table cellpadding = "0" cellspacing = "0">
            <tr>
                <th><?php __('Quien'); ?></th>
                <th><?php __('Acción'); ?></th>
                <th><?php __('Monto'); ?></th>
                <th><?php __('Tipo'); ?></th>
                <th><?php __('Fecha'); ?></th>
                <th class="actions"><?php __('Acciones'); ?></th>
            </tr>
    <?php
    if(empty($cash_movements)){
        ?>
                
        <tr>
            <td colspan="6">No se encontraron Movimientos</td>
        </tr>
    <?php
    }
    
    $i = 0;
    foreach ($cash_movements as $bigCashMovement):
        $cashMovement = $bigCashMovement['BigCashMovement'];
        $class = null;
        if ($i++ % 2 == 0) {
            $class = ' class="altrow"';
        }
        ?>
                <tr<?php echo $class; ?>>
                    <td><?php echo $users[$cashMovement['user_id']]; ?></td>
                    <td>
        <?php
        if ($cashMovement['type'] == 'in') {
            $tipo = 'Entrada';
//                            $total_entradas += $cashMovement['amount'];
        } else {
            $tipo = 'Salida';
//                            $total_salidas += $cashMovement['amount'];
        }
        echo $tipo;
        ?>
                    </td>
                    <td><?php echo '$' . $cashMovement['amount']; ?></td>
                    <td>
        <?php
        switch ($cashMovement['movement']) {
            case 'simple':
                $movimiento = 'Simple';
                break;
            case 'bank':
                $movimiento = 'Depósito Bancario';
                if ($cashMovement['job_id'] != '') {
                    $movimiento .= ' (' . $this->Html->link('Ver Cumpleaños', array('controller' => 'jobs', 'action' => 'view', $cashMovement['job_id'])) . ')';
                }
                break;
            case 'transfer_cash':
                $movimiento = 'Transferencia Caja Chica (' . $this->Html->link('Ver Caja Chica', array('controller' => 'cashes', 'action' => 'view', $cashMovement['cash_id'])) . ')';
                break;
            case 'job_payment':
                $movimiento = 'Pago Saldo Trabajo';
                if ($cashMovement['job_id'] != '') {
                    $movimiento .= ' (' . $this->Html->link('Ver Cumpleaños', array('controller' => 'jobs', 'action' => 'view', $cashMovement['job_id'])) . ')';
                }
                break;
            default:
                $movimiento = '';
                break;
        }
        echo $movimiento;
        ?>
                    </td>
                    <td><?php echo date('d/m/Y H:i:s', strtotime($cashMovement['created'])); ?></td>
                    <td class="actions">
        <?php
        echo $this->Html->link($this->Html->image('icons/magnifier.png'), array('controller' => 'big_cash_movements', 'action' => 'view', $cashMovement['id']), array('title' => __('Ver Detalle', true), 'escape' => false));
        ?>
                    </td>
                </tr>
    <?php endforeach; ?>
        </table>
            <?php
//    echo $this->Form->input('total_entradas', array('type' => 'hidden', 'value' => $total_entradas));
//    echo $this->Form->input('total_salidas', array('type' => 'hidden', 'value' => $total_salidas));
        ?>
</div>
<script type="text/javascript" >

    (function($) {
        // Date picker
        $("#BigCashDateFrom").datepicker({
            //yearRange: '1970:2010',
            defaultDate: new Date(),
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
        });
        // Date picker
        $("#BigCashDateTo").datepicker({
            //yearRange: '1970:2010',
            defaultDate: new Date(),
            dateFormat: 'dd/mm/yy',
            changeMonth: true,
            changeYear: true
        });

    })(jQuery);

    function fecha_semana() {
        var hoy = $('#BigCashHiddenActualDate').val();
        var semana = $('#BigCashHiddenWeekDate').val();
        $('#BigCashDateFrom').val(semana);
        $('#BigCashDateTo').val(hoy);
        $('#BigCashPorDiaForm').submit();
    }
</script>